package dao //此为与数据库联系最近的层

import "new/models"

func GetAllStudent() (error, []models.Student, int64) {
	var StudentData []models.Student
	var total int64
	//从数据库表student中找到主码sno在对其进行操作，以下同理
	err := db.Table("student").Order("sno ASC").Count(&total).Find(&StudentData).Error
	return err, StudentData, total
}
func DelStudent(sno int) error {
	var Student []models.Student
	err := db.Table("student").Where("sno = ?", sno).Delete(&Student).Error
	return err
}
func UpdateStudent(Student models.Student) error {
	err := db.Table("student").Where("sno = ?", Student.Sno).Updates(&Student).Error
	return err
}
func AddStudent(Student models.Student) error {
	err := db.Table("student").Create(&Student).Error
	return err
}
